package com.iswoak.netctoss.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.iswoak.netctoss.dao.RoleModuleDao;
import com.iswoak.netctoss.entity.RoleModule;
import com.iswoak.netctoss.util.DBUtil;

public class RoleModuleDaoImpl implements RoleModuleDao{

	@Override
	public void add(RoleModule roleModule) {
		Connection conn=DBUtil.getConnection();
		PreparedStatement ps=null;
		String sql="insert into role_module (role_id,module_id) values (?,?)";
		try {
			ps=conn.prepareStatement(sql);
			ps.setInt(1, roleModule.getRoleId());
			ps.setInt(2, roleModule.getModuleId());
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.closeConnectionAndPreparedStatement(conn, ps);
		}
	}

	@Override
	public void deleteByRoleId(Integer roleId) {
		Connection conn=DBUtil.getConnection();
		PreparedStatement ps=null;
		String sql="delete from role_module where role_id=?";
		try {
			ps=conn.prepareStatement(sql);
			ps.setInt(1, roleId);
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.closeConnectionAndPreparedStatement(conn, ps);
		}
	}
	
}
